<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script src="./ajax.js"></script>
  <script>
    // myajax({
    //   type: 'GET',
    //   url: 'http://192.168.14.86:3000/article',
    //   data: {},
    //   success: function (res) {
    //     let article = JSON.parse(res)
    //     console.log(article);
    //     myajax({
    //       type: 'GET',
    //       url: 'http://192.168.14.86:3000/author/' + article.authorId,
    //       data: {},
    //       success: function (res1) {

    //         let userDetail = JSON.parse(res1)
    //         myajax({
    //           type: 'GET',
    //           url: 'http://192.168.14.86:3000/address/' + userDetail.birthPlace,
    //           data: {},
    //           success: function (res3) {
    //             console.log(res3);

    //           }
    //         })
    //       }
    //     })
    //   }
    // })

    function getArticle() {
      return new Promise((resolve, reject) => {
        myajax({
          type: 'GET',
          url: 'http://192.168.14.86:3000/article',
          data: {},
          success: function (res) {
            resolve(JSON.parse(res))
          }
        })
      })
    }
    function getUserDetail(article) {
      return new Promise((resolve, reject) => {
        myajax({
          type: 'GET',
          url: 'http://192.168.14.86:3000/author/' + article.authorId,
          data: {},
          success: function (res) {
            console.log(res);
            resolve(JSON.parse(res))
          }
        })
      })
    }
    function getAddressDetail(userDetail) {
      return new Promise((resolve, reject) => {
        myajax({
          type: 'GET',
          url: 'http://192.168.14.86:3000/address/' + userDetail.birthPlace,
          data: {},
          success: function (res) {
            resolve(JSON.parse(res))
          }
        })
      })
    }

    let p = getArticle()

    p
      .then(article => {
        return getUserDetail(article)
      })
      .then(userDetail => {
        return getAddressDetail(userDetail);
      })
      .then(res => {
        console.log(res);
      })
      .catch(err => {
        console.log(err);
      })


  </script>
</body>

</html>